import { useState, useEffect } from 'react';
import axios from 'axios';

export const useLunxun = () => {
  const [string, setstring] = useState('');
  const startAxiosLong = () => {
    var timer: any;
    axios
      .get(
        'https://rapserver.sunmi.com/app/mock/628/GET/%2Fexample%2F1627624943056',
      )
      .then((res) => {
        if (res) {
          console.log(res, 'res');
          timer = setTimeout(() => {
            setstring(() => {
              return res.data.data[0].item;
            });
            startAxiosLong();
            clearTimeout(timer);
          }, 5000);
        } else {
          clearTimeout(timer);
        }
      });
  };
  return { string, startAxiosLong };
};
